package com.ruoyi.web.controller.other;

import com.ruoyi.committee.domain.HouseCommitteeT;
import com.ruoyi.committee.service.IHouseCommitteeTService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业主委员会Controller
 * 
 * @author ruoyi
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/other/committee")
public class HouseCommitteeTController extends BaseController
{
    @Autowired
    private IHouseCommitteeTService houseCommitteeTService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询业主委员会列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseCommitteeT houseCommitteeT)
    {
        startPage();
        List<HouseCommitteeT> list = houseCommitteeTService.selectHouseCommitteeTList(houseCommitteeT);
        return getDataTable(list);
    }

    /**
     * 导出业主委员会列表
     */
    @Log(title = "业主委员会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseCommitteeT houseCommitteeT)
    {
        List<HouseCommitteeT> list = houseCommitteeTService.selectHouseCommitteeTList(houseCommitteeT);
        ExcelUtil<HouseCommitteeT> util = new ExcelUtil<HouseCommitteeT>(HouseCommitteeT.class);
        util.exportExcel(response, list, "业主委员会数据");
    }

    /**
     * 获取业主委员会详细信息
     */
   @GetMapping(value = "/{committeeId}")
    public AjaxResult getInfo(@PathVariable("committeeId") Long committeeId)
    {
        return AjaxResult.success(houseCommitteeTService.selectHouseCommitteeTByCommitteeId(committeeId));
    }

    /**
     * 新增业主委员会
     */
     @Log(title = "业主委员会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseCommitteeT houseCommitteeT)
    {
        houseCommitteeT.setCreater(getUsername());
        return toAjax(houseCommitteeTService.insertHouseCommitteeT(houseCommitteeT));
    }

    /**
     * 修改业主委员会
     */
    @Log(title = "业主委员会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseCommitteeT houseCommitteeT)
    {
        return toAjax(houseCommitteeTService.updateHouseCommitteeT(houseCommitteeT));
    }

    /**
     * 删除业主委员会
     */
    @Log(title = "业主委员会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{committeeIds}")
    public AjaxResult remove(@PathVariable Long[] committeeIds)
    {
        return toAjax(houseCommitteeTService.deleteHouseCommitteeTByCommitteeIds(committeeIds));
    }
}
